﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Correct brackets</title>
	<link href="styles/js-console.css" rel="stylesheet" />
	<script src="scripts/string-extensions.js"></script>
</head>
<body>							  

	<label for="expression">Write an expression and check for correctly put brakets</label>
	<input id="expression" type="text" class="js-console-input" />
	<a href="#" class="js-console-btn" onclick="printResult()">Check Brakets</a>
	<div id="js-console"></div>
	<script src="scripts/js-console.js"></script>
	<script>

	    function printResult() {
	        var expr = jsConsole.read("#expression");
	        var leftBraketsCount = checkBrakets(expr, "(");
	        var rightBraketsCount = checkBrakets(expr, ")");
	        if (leftBraketsCount === rightBraketsCount) {
	            jsConsole.writeLine("The brackets count is all right: " + leftBraketsCount);
	        }
	        else {
	            jsConsole.writeLine("The brackets counts is wrong!There are " + leftBraketsCount + " left brackets and " + rightBraketsCount + " right!");
	        }

	    }
	    function checkBrakets(expr, braket) {
	        var count = 0;
	        for (var i = 0; i < expr.length; i++) {
	            if (expr[i] == braket) {
	                count++;
	            }
	        }
	        return count;
	    }


	</script>

</body>
</html>